package com.br4mmie.asciistory.ui;

import com.br4mmie.asciistory.CharImage;
import com.br4mmie.asciistory.mission.Mission;
import com.br4mmie.asciistory.mission.Mission.Objective;


public class MissionWindow extends Window 
{
	private Mission mission;
	
	public MissionWindow(Mission mission)
	{
		super(2, 2, 46, 11);
		this.mission = mission;
	}
	
	public void draw(CharImage target)
	{
		image.fill(' ');

		int x = 1;
		for (char c: mission.getName().toCharArray())
		{
			image.putChar(c, x++, 1);
		}
		image.line('-', 1, 2, image.getWidth(), 2);
		
		x = 1;
		int y = 3;
		for (char c: "Objectives:".toCharArray())
		{
			image.putChar(c, x++, y);
			if (x > image.getWidth()-5) {x = 1; y++;}
		}
		if (x>1) {x=1;y++;}
		for (Mission.Objective objective: mission.getObjectives())
		{
			image.putChar('*', x++, y);
			image.putChar(' ', x++, y);
			for (char c: objective.toString().toCharArray())
			{
				if (c == '\n') 
				{
					if (x > 1)
					{
						x = 1;
						y++;
					}
				}
				else
				{
					image.putChar(c, x++, y);
					if (x > image.getWidth()-5) {x = 1; y++;}
				}
			}
			if (x>1) {x=1;y++;}
		}
		
		super.draw(target);
	}
}
